<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
	prefix="decorator"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<decorator:usePage id="mainPage" />
<html>
<head>
<link href="<s:url value='/css/not-ie.css' />" rel="stylesheet"
	type="text/css">
<script language="javascript" src="<s:url value='/js/control.js' />"></script>
<script type="text/javascript"
	src="<s:url value='/jquery-ui-1.10.3.custom/js/jquery-1.9.1.js' />"></script>
<script type="text/javascript"
	src="<s:url value='/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.js' />"></script>
<link rel="stylesheet"
	href="<s:url value='/jquery-ui-1.10.3.custom/css/ui-lightness/jquery-ui-1.10.3.custom.css' />" />
<script language="javascript">
$(function() {
    $("#harvestDateFrom" ).datepicker();
    $("#harvestDateTo").datepicker();
  });
  
function sf(){
	document.getElementsByName("criteria.harvestId")[0].focus();
}
	function searchPage(){
		frm = document.harvestForm;
		frm["criteriaKey"].value = "";
		frm.action = "<s:url value='/searchHarvest.action'/>";
		frm.submit();
		}

	function gotoAdd(){
			frm = document.harvestForm;
			frm.action = "<s:url value='/gotoAddHarvest.action'/>";
			frm.submit();
		}

	function gotoEdit(id){
		frm = document.harvestForm;
		//set ค่า id ลงใน member.memberId
		frm.action = "<s:url value='/searchByIdHarvest.action'/>?harvestIds="+id+"&page=edit";
		frm.submit();
		}

	function gotoView(id){
		frm = document.harvestForm;
		//set ค่า id ลงใน member.memberId
		frm.action = "<s:url value='/searchByIdHarvest.action'/>?harvestIds="+id+"&page=view";
		frm.submit();
		}

	function deletes(chkName){
		var chk = false;
		chk = chkSellock(chkName);
		if(chk == false){alert('<s:text name="0007" />');return;}
		if(!confirm('<s:text name="0008" />')){
			return false;
		} 
		var ids="";
		for(i=0;i<document.getElementsByName(chkName).length;i++){
			if(document.getElementsByName(chkName)[i].checked==true){
				ids+=","+document.getElementsByName(chkName)[i].value;
			}
		}
	      
		frm = document.harvestForm;
		frm.action="<s:url value='/deleteHarvest.action' />?harvestIds="+ids.substring(1);
		frm.submit();
	}
	function clearPage(){
		frm = document.harvestForm;
		frm.action="<s:url value='/clearHarvest.action' />";
		frm.submit();
	}
	function switchAll(chkName,val){
		var chk = document.getElementsByName(chkName);
		for (var i=0; i<chk.length; i++){
			if(chk[i].disabled != true){//enable object
				chk[i].checked = val;
			}
		}
	}
	function chkSellock(chkName){
		var chk = document.getElementsByName(chkName);
		for (var i=0; i<chk.length; i++)
		{if (chk[i].checked == true) {return true;}}
		return false;
	}
</script>
</head>
<body>
	<h1>ค้นหาข้อมูลการเก็บเกี่ยว</h1>
	<s:form method="post" id="harvestForm" name="harvestForm"
		onsubmit="searchPage();">
		<s:submit cssClass="submit" id="submitId" />
		<table class="authen">
			<tr>
				<td class="left">
				</td>
				<td class="center"><s:property value="#request.message" /></td>
				<td class="right"></td>
			</tr>
		</table>
		<table class="form" border="0">
			<tr style="height: 0px;">
				<td class="col-width-100px"></td>
				<td class="col-width-175px"></td>
				<td class="col-width-175px"></td>
				<td class="col-width-125px"></td>
				<td class="col-width-175px"></td>
				<td class="col-width-auto"></td>
			</tr>

			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
				<td align="right">รหัสการเก็บเกี่ยว&nbsp;&nbsp;&nbsp;&nbsp;</td>
				<td><s:textfield name="criteria.harvestId" /></td>
				<td align="right">แปลง&nbsp;&nbsp;&nbsp;&nbsp;</td>
				<td><s:select name="criteria.harvestArea" headerKey=""
						headerValue="%{getText('msg.all')}" list="lstArea" size="1" /></td>

			</tr>
			<tr>
				<td></td>
				<td align="right"></td>
				<td></td>
				<td align="right"></td>
				<td></td>

			</tr>
			<tr>
				<td></td>
				<td align="right">การเก็บเกี่ยวตั้งแต่วันที่&nbsp;&nbsp;&nbsp;&nbsp;</td>
				<td><s:textfield name="criteria.harvestDateFrom"
						id="harvestDateFrom" /></td>
				<td align="right">ถึงวันที่&nbsp;&nbsp;&nbsp;&nbsp;</td>
				<td><s:textfield name="criteria.harvestDateTo"
						id="harvestDateTo" /></td>
			</tr>
		</table>
		<table class="button">
			<tr>
				<td class="left"></td>
				<td class="right"><input type="button" id="btnSearch"
					onclick="javascript:searchPage();"
					value="<s:text name="msg.search"></s:text>" class="btnSearch" /> <input
					type="button" id="btnClear" onclick="javascript:clearPage();"
					value="<s:text name="msg.clearScreen"></s:text>"
					onkeydown="return doTabFocus('employeeCode','',event,true);"
					class="btnClear" /></td>
			</tr>
		</table>
		<s:if test="%{lstSearch.size() > 0}">
			<div  style="width:100%;  overflow-x: scroll;height: 260px; overflow-y:hidden;border:0px;">
				<table class="result">
					<thead>
						<tr>
							<th class="order"><s:text name="no" /></th>
							<th class="checkbox"><input type="checkbox" name="chkAll"
								onClick="switchAll('harvestIds',checked)" /></th>
							<th class="col-width-100px"><s:text name="แปลง" /></th>
							<th class="col-width-100px"><s:text name="จำนวน" /></th>
							<th class="col-width-100px"><s:text name="วันที่การก็บเกี่ยว" /></th>
							<th class="col-width-100px"><s:text name="รอบที่" /></th>
							<th class="edit"><s:text name="แก้ไข" /></th>
							<th class="view"><s:text name="แสดง" /></th>

						</tr>
					</thead>
				</table>
				<div style="border-left:none;overflow-y:scroll;overflow-x:hidden;height:220px;*height:215px;width:1005px;">
				<table class="result">
					<tbody>
						<s:iterator value="lstSearch" status="status" var="result">

							<tr>
								<td class="order"><s:property value="#status.index+1" /></td>
								<td class="checkbox">
									<input type="checkbox" name="harvestIds"
										value="<s:property value='#result.harvestId' />pp<s:property value="#result.harvestAreaId"/>dd<s:property value="#result.plantingStatus"/>" /></td>
								<td class="col-width-100px text">
									<s:property value='#result.harvestArea' />
										<input type="hidden" name="harvest.harvestAreaId" value='<s:property value="#result.harvestAreaId"/>'/>
								</td>
								<td class="col-width-100px text"><s:property
										value='#result.harvestValue' /></td>
								<td class="col-width-100px text"><s:property
										value='#result.harvestDate' /></td>
								<td class="col-width-100px text">
									<s:if test="#result.plantingStatus == 4">
									    รอบที่ 1
									</s:if>
									<s:else>
									    รอบที่ 2
									</s:else>
									<input type="hidden" name="harvest.plantingStatus" value='<s:property value="#result.plantingStatus"/>'/>
								</td>
								<td class="edit"><a href="javascript:void(0);"
									onclick="javascript:gotoEdit('<s:property value='#result.harvestId' />');">
										<img src="<s:url value='/images/icon/i_edit.gif'/>">
								</a></td>
								<td style="width: 48px;text-align: center;" >
								<a href="javascript:void(0);"
									onclick="javascript:gotoView('<s:property value='#result.harvestId' />');">
										<img src="<s:url value='/images/icon/i_view.gif' />">
								</a></td>

							</tr>
						</s:iterator>
					</tbody>
				</table>
			</div>
			</div>
			<table class="result">
				<tfoot>
					<tr class="footer">
						<td><a class="action-link" href="javascript:void(0);"
							onclick="javascript:deletes('harvestIds');"><img
								src="<s:url value='/images/icon/i_del.gif' />">&nbsp;<s:text
									name="msg.delettb" /></a>&nbsp;&nbsp;</td>
					</tr>
				</tfoot>
			</table>
		</s:if>
		<s:hidden name="criteriaKey" />
	</s:form>
</body>
</html>